<?php
include("../inc/classes/install.class.php");
include("../inc/util.php");
header('Content-Type: text/html; charset=utf-8');		
if (file_exists('../inc/config.php')) {
   	exit(message('系统已经安装，如重新安装请删除“inc” 目录下的"config.php"文件'));
}
elseif (isset($_GET['install'])) {	
	

	if(empty($_POST['webname'])){exit(message('网站名称不能为空'));} else {$webName = $_POST['webname'];}
	if(empty($_POST['adminname'])){exit(message('管理员账号不能为空'));} else {$admin = $_POST['adminname'];}
	if(empty($_POST['adminpass'])){exit(message('管理员密码不能为空'));} else {$adminPass = $_POST['adminpass'];}
	
	if(empty($_POST['localhost'])){exit(message('服务器地址不能为空'));} else {$host = $_POST['localhost'];}
	if(empty($_POST['hostdatabase'])){exit(message('数据库名称不能为空'));} else {$database = $_POST['hostdatabase'];}
	if(empty($_POST['user'])){exit(message('数据库帐号不能为空'));} else {$user = $_POST['user'];}
	if(empty($_POST['pass'])){exit(message('数据库密码不能为空'));} else {$pass = $_POST['pass'];}
	
	if(empty($_POST['smtpHost'])){exit(message('邮件服务器不能为空'));} else {$smtpHost = $_POST['smtpHost'];}
	if(empty($_POST['smtpUser'])){exit(message('邮件服务器登录帐号不能为空'));} else {$smtpUser = $_POST['smtpUser'];}
	if(empty($_POST['smtpPass'])){exit(message('邮件服务器登录密码不能为空'));} else {$smtpPass = $_POST['smtpPass'];}
	if(empty($_POST['smtpFromName'])){exit(message('邮件服务器发件人名称不能为空'));} else {$smtpFromName = $_POST['smtpFromName'];}
	
	$pageNum = empty($_POST['pagesize']) ? 10 : intval($_POST['pagesize']);
	$act = new InstallMysqlTable($host,$user ,$pass ,$database ,$pageNum , $admin , $webName,$smtpHost,$smtpUser,$smtpPass,$smtpFromName);
	 if (false == $act->state) {
	 	exit(message("数据库连接失败！"));
	 }else {
	 	$act->insertTable(); //创建表
	 	$act->insertBasicData($admin , $adminPass); //插入基本数据
	 	$act->insertWriteConfig();//创建配置文件
	 	Header("Location:../index.php");
	 }    	 
	exit;
}else {
	include("gui.html");
}
?>

